<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PrevisionEnteteJsonService
 *
 * @author ingeni
 */
class PrevisionEnteteJsonService {
    //put your code here
    
    public function create(ContextExecution $p_contexte){
        //$mode=$p_contexte->m_dataRequest->getData('mode');
        $entete = new Prevision();
        $entete->fieldObject($p_contexte->m_dataRequest);
        $entete->save();
    
        $identete=$entete->lastInsertId();
        $entete->ligneId = $identete;
        PrevisionCommun::genereLignes($entete, $identete, 1, 0, $p_contexte->m_dataRequest->getData('montant'));
        
        $p_contexte->addDataBlockRow($entete);
    }
    
    /**
     * 
     * Enter description here ...
     * @param ContexteExecution $p_contexte
     */
    public function display(ContextExecution $p_contexte){
    	$liste = new ListDynamicObject();
    	$liste->name='ListeEntete';
    	$annee=$p_contexte->m_dataRequest->getData('annee');
    	$numeroCompte=$p_contexte->m_dataRequest->getData('noCompte');
    	
    	/*$l_clause ="nocompte='$numeroCompte' AND annee='$annee' and typenr='E'";
    	$ligneId=$p_contexte->m_dataRequest->getData('ligneId');
        
    	if($ligneId!=null && $ligneId!=''){
        	$clause .=" AND ligneid=$ligneId";
        }*/
    	
        $l_requete="SELECT fluxid, flux FROM flux WHERE compteId='$numeroCompte' AND EXISTS(SELECT 1 FROM prevision WHERE prevision.noCompte=flux.compteId AND typenr='E' AND prevision.annee='$annee' AND prevision.fluxid=flux.fluxid)";
        
        //SELECT fluxid, flux WHERE compteId='' AND EXISTS(SELECT 1 FROM prevision WHERE noCompte=flux.compteId AND annee='' AND fluxid=flux.fluxid)
        
        
    	//$liste->request('Prevision', $l_clause, 1);
    	
        $liste->request($l_requete);
        
    	$p_contexte->addDataBlockRow($liste);
    }
    
}

?>
